package com.galeno.zoopeeper;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

import java.io.IOException;

/**
 * @author galeno @Title: @Description:
 * @date 2021/7/3016:51
 */
public class Demo2 {
  public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
    ZooKeeper zk = new ZooKeeper("galeno01:2181", 2000, null);
    /** 判断节点是否存在 ,为null则不存在 */
    Stat stat = zk.exists("/zookeeper", null);
    if (stat != null) {

      // 字节数据   在ZK中存储的数据类型是字节
      byte[] data = zk.getData("/ccc", null, null);

      String s = new String(data);
      System.out.println(s);

    } else {
      System.out.println("节点不存在");
    }
    zk.close();
  }
}
